var e, t = require("../../@babel/runtime/helpers/interopRequireDefault"),
  a = t(require("../../@babel/runtime/regenerator")),
  i = t(require("../../@babel/runtime/helpers/asyncToGenerator")),
  base = require("../../base.js"),
  u = getApp(),
  o = null;
var list = require("../../datas/list.js");
Page({
  data: {
    douyin: base.IMGPATH + "but_douyin.png",
    icons: {
      del: base.IMGPATH + "del.png",
      ic_search: base.IMGPATH + "ic_search.png",
      ic_delete: base.IMGPATH + "ic_delete.png",
      ic_hot: base.IMGPATH + "ic_hot.png",
      no: base.IMGPATH + "no.png",
      back: base.IMGPATH + "back.png"
    },
    keyWord: "",
    winHeight: "",
    pageNumber: 1,
    pageSize: 10,
    questionCategory: "",
    list: [],
    fetchDataDone: !1,
    status: !1
  },
  onLoad: function () {
    this.setData({
      winHeight: u.globalData.winHeight - 322
    }), wx.showLoading({
      title: "加载中"
    }), this.fetchData();
  },
  fetchData: (e = (0, i.default)(a.default.mark(function e() {
    var t, i, n, u, o, c, l, d, h, g;
    return a.default.wrap(function (e) {
      for (;;) switch (e.prev = e.next) {
        case 0:
          return t = !1, i = this.data, n = [], u = i.keyWord, o = i.pageNumber, c = i.pageSize,
            l = i.questionCategory, e.next = 4, (0, base.ajax)({
              url: "/api/testQuestion/getPager",
              data: {
                keyWord: u,
                pageSize: c,
                pageNumber: o,
                questionCategory: l
              }
            });

        case 4:
          d = e.sent;
          if (!d) {
            e.next = "end";
            wx.hideLoading();
            break;
          }
          if (wx.hideLoading(), d.code) {
            e.next = 16;
            break;
          }
          h = d.data;
          if (!h) {
            h = list.filter((e) => !u || e.title.includes(u));
            e.next = 10;
            wx.hideLoading();
            break;
          }
          if (h = d.data.length) {
            e.next = 10;
            break;
          }
          return e.abrupt("return");

        case 10:
          for (h.length >= c && (o++, t = !0), g = 0; g < h.length; g++) h[g].reads = (0,
            base.getRandomNumberByRange)(1e3, 1e5);
          n = n.concat(h), this.setData({
            pageNumber: o,
            list: n,
            status: t,
            fetchDataDone: !0
          }), e.next = 17;
          break;

        case 16:
          this.setData({
            fetchDataDone: !0,
            status: !1
          });

        case 17:
          return e.abrupt("return", t);

        case 18:
        case "end":
          return e.stop();
      }
    }, e, this);
  })), function () {
    return e.apply(this, arguments);
  }),
  lowerScroll: function (e) {
    this.data.status && this.fetchData();
  },
  backHandle: function () {
    wx.navigateBack({
      delta: 1
    });
  },
  clearHandle: function () {
    var e = this;
    this.setData({
      list: [],
      keyWord: "",
      pageNumber: 1
    }, function () {
      e.fetchData();
    });
  },
  searchHandle: function () {
    var e = this;
    this.data.keyWord && (wx.showLoading({
      title: "搜索中"
    }), this.setData({
      list: [],
      pageNumber: 1
    }, function () {
      e.fetchData();
    }));
  },
  handleInput: function (e) {
    var t = this;
    o && clearTimeout(o), o = setTimeout(function () {
      var a = e.detail.value;
      t.setData({
        keyWord: a
      }, function () {
        a || t.fetchData();
      });
    }, 300);
  },
  handleConfirm: function (e) {
    var t = this,
      a = e.detail.value;
    this.setData({
      keyWord: a
    }, function () {
      a || t.fetchData();
    });
  },
  jumpDetail: function (e) {
    var t = e.currentTarget.dataset.id;
    if (!t) throw new Error("detail id 缺失");
    wx.navigateTo({
      url: "/pages/detail/index?id=" + t
    });
  }
});